package com.ll.app.controller;

import com.ll.app.api.req.AddShopReqDTO;
import com.ll.base.dto.ApiResultDTO;
import com.ll.base.dto.PageReqDTO;
import com.ll.domain.shop.biz.GoodsDomainService;
import com.ll.domain.shop.biz.ShopDomainService;
import com.ll.domain.shop.dto.ShopDTO;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

@Slf4j
@RestController
@RequestMapping("/shop")
@RequiredArgsConstructor
@Api(tags = "商铺API")
public class ShopController {

    private final ShopDomainService shopDomainService;

    @ResponseBody
    @ApiOperation(value = "店铺列表")
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public ApiResultDTO page(@RequestBody @Validated PageReqDTO pageReq) {
        return ApiResultDTO.success(shopDomainService.page(pageReq));
    }


    @ResponseBody
    @ApiOperation(value = "添加店铺")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "price", value = "价格", example = "带弓98", required = true),
            @ApiImplicitParam(name = "price1", value = "价格2", example = "不带弓98", required = true),
            @ApiImplicitParam(name = "name", value = "名称", example = "Sin29正弦射箭俱乐部", required = true),
            @ApiImplicitParam(name = "remarks", value = "说明", example = "Sin29正弦射箭俱乐部(庆春广场店) \n" +
                    "  98元的双人半小时无限次射箭体验，一个轮回12支箭，一排四个人，四个人分别发射完12支箭后，自行去靶子那边拔箭，再进行第二轮回，这样半小时估计能玩个四个轮回，进去地方还挺宽敞的，晚上去的快9点了还是有人来玩，这边有老板和助教小姐姐教学，初学者先要学会握箭姿势，安全第一", required = true),
            @ApiImplicitParam(name = "creator", value = "创建者",example = "6015124",  required = true),
            @ApiImplicitParam(name = "address", value = "地址", example = "杭州市上城区四季青街道庆春广场三新大厦1408室", required = true),
            @ApiImplicitParam(name = "contacts", value = "联系人",example = "汪先生",  required = true),
            @ApiImplicitParam(name = "contactNum", value = "联系方式",example = "18689477777",  required = true),
    })
    @RequestMapping(value = "/addShop", method = RequestMethod.POST)
    public ApiResultDTO addShop(
            @RequestParam( "price") String price,
            @RequestParam( "price1") String price1,
            @RequestParam("name") String name,
            @RequestParam("remarks") String remarks,
            @RequestParam( "creator") Long creator,
            @RequestParam("address") String address,
            @RequestParam("contacts") String contacts,
            @RequestParam("contactNum") String contactNum,
            @RequestParam("logo") MultipartFile logo,
            @RequestParam("logo1") MultipartFile logo1) {

        AddShopReqDTO build = AddShopReqDTO.builder()
                .price(price)
                .price1(price1)
                .name(name)
                .address(address)
                .remarks(remarks)
                .creator(creator)
                .contacts(contacts)
                .contactNum(contactNum)
                .build();
        return ApiResultDTO.success(shopDomainService.addShop(build, logo, logo1));
    }
}


